package com.liangzhong.model.leagueMatch.vo
{
	import flash.events.Event;
	import flash.events.EventDispatcher;

	/**
	 *预选赛信息vo 
	 * @author lake
	 * 
	 */	
	public class TrialMatchInfoVo extends EventDispatcher
	{
		/**
		 *打到的比赛index 
		 */		
		public var matchindex		:int;
		/**
		 *获胜场次
		 */		
		public var win				:int;
		/**
		 * 比赛结果信息
		 * {hgoal:1,ggoal:2}
		 * 主场进球数  客场进球数
		 */		
		public var matchResList	:Array = [];
		
		public function TrialMatchInfoVo()
		{
		}
		/**
		 *解析 
		 * @param data
		 * 
		 */		
		public function parse(data:Object):void
		{
			win = data.win;
			matchindex = data.matchindex;
			var obj :Object ;
			matchResList = [];
			for(var i:int = 1;i <= 5;i++)
			{
				obj = {};
				obj.hgoal = data["hgoal" + i];
				obj.ggoal = data["ggoal" + i];
				matchResList.push(obj);
			}
			this.dispatchEvent(new Event(Event.CHANGE));
		}
		/**
		 *更新比赛结果 
		 * @param data
		 * 
		 */		
		public function updateResult(data :Object):void
		{
			var index :int = data.index;
			if(index >= matchResList.length)
			{
				return ;
			}
			var obj :Object = matchResList[index];
			obj.hgoal = data.hgoal;
			obj.ggoal = data.ggoal;
			if(obj.hgoal > obj.ggoal)
			{
				win ++;
			}
			matchindex = index + 1;
			if(matchindex == 5)//预选赛通过
			{
				return;
			}
			this.dispatchEvent(new Event(Event.CHANGE));
		}
	}
}